" Set leader key
noremap <Space> <nop>
let mapleader = " "
let maplocalleader = " "

" Save and Quit
nnoremap <S-s> :w<CR>
nnoremap <S-q> :q<CR>
nnoremap <C-q> :qa<CR>

" Quick Move
noremap <S-h> 5h
noremap <S-j> 5j
noremap <S-k> 5k
noremap <S-l> 5l
noremap <S-w> 5w
noremap <S-b> 5b
nnoremap <expr>m col(".")==col("$")-1 ? "^" : "$"
xnoremap <expr>m col(".")==col("$")-1 ? "^" : "$h"

" Move text up and down
xnoremap <C-j> :move '>+1<CR>gv-gv
xnoremap <C-k> :move '<-2<CR>gv-gv
xnoremap p "_dP
xnoremap P "_dp

" Better Tab navigation
nnoremap tn :tabe<CR>
nnoremap tl :+tabnext<CR>
nnoremap th :-tabnext<CR>

" Better Window navigation
nnoremap <LEADER>h <C-w>h
nnoremap <LEADER>j <C-w>j
nnoremap <LEADER>k <C-w>k
nnoremap <LEADER>l <C-w>l

" Press space twice to quickly get into the popup window
noremap <LEADER><LEADER> <C-w><C-w>

" Splite windows
nnoremap <LEADER>s :split<CR>
nnoremap <LEADER>v :vsplit<CR>

" Resize windows
nnoremap <up> :res -5<CR>
nnoremap <down> :res +5<CR>
nnoremap <left> :vertical resize-5<CR>
nnoremap <right> :vertical resize+5<CR>

" Indentation
nnoremap < <<
nnoremap > >>
vnoremap < <gv
vnoremap > >gv

" Close highlight
nnoremap <silent> <LEADER>/ :nohlsearch<CR>

" Toggle spell check
nnoremap <LEADER>cs :set spell!<CR>

" Toggle current terminal
nnoremap <C-\> :FloatermToggle<CR>
" more easy to use terminal
tnoremap <C-N> <C-\><C-N>
tnoremap <C-O> <C-\><C-N>:q<CR>

" File explorer
nnoremap <silent> <LEADER>e :CocCommand explorer<CR>

" Tabular
xnoremap t\ :Tabularize \

" Visual make to line end
nnoremap <silent> \v v$h

" Find and replace
nnoremap \s :%s//g<Left><Left>

" Folding
nnoremap <silent> <LEADER>o za

" GitSign
nnoremap <silent> <LEADER>H :SignifyHunkDiff<CR>

" Clipboard history
nnoremap <silent> <LEADER>y  :<C-u>CocList -A --normal yank<cr>

" Copy to system clipboard
xnoremap Y "+y
